package com.walk.zworld.mvvm.vm

import androidx.lifecycle.LiveData
import com.base.lib.httpUtils.BaseListResponseBody
import com.base.lib.httpUtils.CoinInfoBean
import com.base.lib.httpUtils.UserInfoBody
import com.walk.zworld.mvvm.repository.ScoreRepository
import com.base.lib.base.event.SingleLiveEvent
import com.base.lib.base.mvvm.viewmodel.BaseRefreshViewModel

class MyRankActivityViewModel : BaseRefreshViewModel<CoinInfoBean>() {

    private val repository = ScoreRepository()
    private val userInfo = SingleLiveEvent<UserInfoBody>()
    private val rankList = SingleLiveEvent<BaseListResponseBody<CoinInfoBean>>()

    fun getUserInfo(): LiveData<UserInfoBody> {
        launchUI {
            val result = repository.getUserInfo()
            userInfo.value = result.data
        }
        return userInfo
    }


    fun getRankList(page: Int): LiveData<BaseListResponseBody<CoinInfoBean>> {
        launchUI {
            val result = repository.getRankList(page)
            rankList.value = result.data
            mData.value = result.data.datas
        }
        return rankList
    }

    override fun refreshData(params: Any?) {
        getRankList(page=0)
    }

    override fun loadMore(params: Any?) {
        getRankList(page++)
    }
}